package com.css.fxfzdpzs.modules.czt.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdpzs.base.response.RestResponse;
import com.css.fxfzdpzs.modules.czt.entity.first.CztProvinceVulnerabilityCount;
import com.css.fxfzdpzs.modules.czt.entity.first.CztSmgcVulnerabilityNum;
import com.css.fxfzdpzs.modules.czt.entity.second.*;
import com.css.fxfzdpzs.modules.czt.param.ProbabilisticEarthquakeParam;
import com.css.fxfzdpzs.modules.czt.vo.*;
import com.css.fxfzdpzs.modules.czt.service.CztService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.*;

/**
 * @author y1fan
 * @description czt   目前地图接口未写
 */
@RestController
@RequestMapping("/czt")
@Slf4j
public class CztController {


    @Resource
    private CztService cztService;


    /**
     * 承灾体 （一级目录）  7.1.65单体建筑物易损性数量
     * czt_number_of_individual_buildings    已完成
     *
     * @return
     */
    @GetMapping("/getBuildNum")
    public RestResponse getBuildNum() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            CztMonomerBuildNumVO cztMonomerBuildNumVO = cztService.getBuildNum();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(cztMonomerBuildNumVO);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 承灾体 （一级目录）  7.1.66易损性数据分省统计
     * czt_vulnerability_of_lifelines   已完成
     *
     * @return
     */
    @GetMapping("/getVulnerabilityCount")
    public RestResponse getVulnerabilityCount() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<CztProvinceVulnerabilityCount> cztProvinceVulnerabilityCounts = cztService.getVulnerabilityCount();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(cztProvinceVulnerabilityCounts);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 承灾体 （一级目录）  查询哪些省份有综合易损性曲线
     * czt_beijing_vulnerability_curve
     *
     * @return
     */
    @GetMapping("/getProvince")
    public RestResponse getProvince() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<String> list = cztService.getProvince();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 承灾体 （一级目录）  7.1.67北京市综合易损性曲线
     * czt_beijing_vulnerability_curve
     *
     * @return
     */
    @GetMapping("/getVulnerabilityCurve")
    public RestResponse getVulnerabilityCurve(String province) {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            CztBeijingVulnerabilityCurveVO vo = cztService.getVulnerabilityCurve(province);
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(vo);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 承灾体 （一级目录）  7.1.68生命线工程及重大基础设施易损性数量
     * czt_number_of_lifelines    已完成
     *
     * @return
     */
    @GetMapping("/getVulnerabilityNum")
    public RestResponse getVulnerabilityNum() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            List<CztSmgcVulnerabilityNum> cztSmgcVulnerabilityNums = cztService.getVulnerabilityNum();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(cztSmgcVulnerabilityNums);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    /**
     * 承灾体 （一级目录）  7.1.69建筑物易损性综合统计（全国）
     * czt_build_vulnerability_count  已完成
     *
     * @return
     */
    @GetMapping("/getBuildVulnerabilityNum")
    public RestResponse getBuildVulnerabilityNum() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            Map<String, Object> map = cztService.getBuildVulnerabilityNum();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 承灾体 （一级目录）全国承灾体易损性访问统计
     * czt_collection_system_situation
     *
     * @return
     */
    @GetMapping("/getSystemSituation")
    public RestResponse getSystemSituation() {
        RestResponse restResponse = null;
        JSONObject jsonObject = new JSONObject();
        try {
            CztSystemSituationVO cztSystemSituationVO = cztService.getSystemSituation();
            jsonObject.put("message", "查询成功!");
            restResponse = RestResponse.succeed(cztSystemSituationVO);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }


    //**************二级页面**************

    //各省不同破坏等级对比
    @GetMapping("/getProportion")
    public RestResponse getProportion() {
        RestResponse restResponse = null;
        try {
            List<DamageGrade> damageGrades = cztService.getProportion();
            restResponse = RestResponse.succeed(damageGrades);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //**************地图**************
    //返回各省易损性完备度（0~1）    VulnerabilityCompletenessVo
    @GetMapping("/getCompleteness")
    public RestResponse getCompleteness() {
        RestResponse restResponse = null;
        try {
            List<VulnerabilityCompletenessVo> list = cztService.getCompleteness();
            restResponse = RestResponse.succeed(list);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    //返回抗震能力（xx度基本完好、xx度轻微破坏、xx度中等破坏、xx度严重破坏、xx度倒塌）对应的省列表，xx=6/7/8/9/10
    @GetMapping("/getSeismicResistance")
    public RestResponse getSeismicResistance(@RequestParam String level) {
        RestResponse restResponse = null;
        try {
            Map<String, List<SeismicResistance>> map = cztService.getSeismicResistance(level);
            restResponse = RestResponse.succeed(map);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 三级页面，概率地震   已完成
     * @param param
     * @return
     */
    @PostMapping("getPsCurve")
    public RestResponse getPsCurve(@RequestBody ProbabilisticEarthquakeParam param) {
        try {
            PeCurveVo peCurveVo = cztService.getPsCurve(param);
            return RestResponse.succeed(peCurveVo);
        } catch (Exception e) {
            return RestResponse.fail("查看失败!");
        }
    }

    /**
     * 二级页面  抗震能力分布图
     * @return
     */
    @GetMapping("seismicResistance")
    public RestResponse seismicResistance(){
        try {
            List<DestructiveStateVo> list = cztService.seismicResistance();
            return RestResponse.succeed(list);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return RestResponse.fail("查看失败!");
        }
    }

    /**
     * 获取曲线
     * @return
     */
    @GetMapping("getCurve")
    public RestResponse getCurve(){
        try {
            HashMap<String, Object> map = cztService.getCurve();
            return RestResponse.succeed(map);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return RestResponse.fail("查看失败!");
        }
    }

    /**
     * 二级页面  不同破坏等级对比
     */
    @GetMapping("ysxComplete")
    public RestResponse ysxComplete(){
        try {
            HashMap<String, Object> map = cztService.ysxComplete();
            return RestResponse.succeed(map);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            return RestResponse.fail("查看失败!");
        }
    }
}
